<template>
<div style="width: 70%">
    <div style="margin-bottom: 30px">编辑图书</div>
    <el-form :inline="true" :model="form" label-width="120px">
        <el-form-item label="名称" prop="name" >
            <el-input v-model="form.name" placeholder="请输入名称"></el-input>
        </el-form-item>
        <el-form-item label="描述"  prop="description">
            <el-input  style="width: 200px ;" :rows="1" type="textarea" v-model="form.description" placeholder="请输入备注"></el-input>
        </el-form-item>
        <el-form-item label="出版日期"  prop="remark">
            <div class="block">
                <el-date-picker
                        v-model="form.publishDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择出版日期">
                </el-date-picker>
            </div>
        </el-form-item>
        <el-form-item label="作者"  prop="remark">
            <el-input v-model="form.author" placeholder="请输入备注"></el-input>
        </el-form-item>
        <el-form-item label="出版社"  prop="remark">
            <el-input v-model="form.publisher" placeholder="请输入备注"></el-input>
        </el-form-item>
        <el-form-item label="分类"  prop="remark">
            <el-cascader
                    :props="{value:'name', label:'name'}"
                    v-model="form.categories"
                    :options="categories"
                    ></el-cascader>
        </el-form-item>
        <el-form-item label="标准码"  prop="remark">
            <el-input v-model="form.bookNo" placeholder="请输入备注"></el-input>
        </el-form-item>
        <el-form-item label="封面"  prop="remark">
            <el-input v-model="form.cover" placeholder="请输入备注"></el-input>
        </el-form-item>
    </el-form>
    <div style="text-align: center  ;margin-top:5px ">
        <el-button type="primary" @click="update" size="medium">提交</el-button>
        <el-button type="info" @click="$router.push('/BookList')" size="medium">返回</el-button>
    </div>
</div>
</template>

<script>
    import request from "@/util/request";
    export default {

        name: "EditBook",
        data(){
            return{
                categories:[],
                form:{}
            }
        },
        created() {
            request.get("/category/tree").then(res=>{
                this.categories=res.data
            })
            const id=this.$route.query.id
            request.get("/book/"+id).then(res=>{
                this.form=res.data
                if(this.form.category){
                    this.form.categories=this.form.category.split(">")
                }
            })
        },
        methods:{
            update(){
                request.put("/book/update",this.form).then(res=>{
                    if (res.code=="200"){
                        this.$notify.success("修改成功")
                        this.$router.push("/BookList")
                    }else{
                        this.$notify.error(res.msg)
                    }
                })
            }
        }
    }
</script>

<style scoped>

</style>
